#!/bin/bash
# Alexander 'Deepy' Nordlund totally made this.

MACHINE_TYPE=`uname -m`
OS_TYPE=`uname`
MYRUNLEVEL=0

if [ ${VIRTUAL_ENV} ]; then
MYRUNLEVEL=1
 if [ `which svn` ]; then
 MYRUNLEVEL=2
  if [ `which hg` ]; then
  MYRUNLEVEL=3
  wget -O requirements.txt --no-check-certificate https://cyanox.nl/peragro/branches/assetserver/scripts/deployment/reqs-hg.txt
  else
   wget -O requirements.txt --no-check-certificate https://cyanox.nl/peragro/branches/assetserver/scripts/deployment/reqs-http.txt
  fi
 else
  echo "[DAMN] Please install SVN."
 fi
else
echo "[DAMN] Please install and start a virtualenv."
fi

if [ ${MYRUNLEVEL} -gt 1 ]; then
 pip install -r requirements.txt
 svn co https://cyanox.nl/peragro/branches/b2.5cs/ b2.5cs
 svn co https://cyanox.nl/peragro/branches/assetserver/ assetserver


if [ ${OS_TYPE} == 'Linux' ]; then
 echo "[DAMN] You appear to be running Linux."
 if [ ${MACHINE_TYPE} == 'x86_64' ]; then
  ## 64bit
  echo "[DAMN] And 64bit, getting 64bit Blender"
  wget http://download.blender.org/release//Blender2.56abeta/blender-2.56a-beta-linux-glibc27-x86_64.tar.bz2
  tar -jxvf blender-2.56a-beta-linux-glibc27-x86_64.tar.bz2
 else
  ## 32bit most likely.
  echo "[DAMN] And 32bit or other, picking 32bit to be sure."
  wget http://download.blender.org/release//Blender2.56abeta/blender-2.56a-beta-linux-glibc27-i686.tar.bz2
  tar -jxvf blender-2.56a-beta-linux-glibc27-i686.tar.bz2
 fi
elif [ ${OS_TYPE} == 'FreeBSD' ]; then
 echo "[DAMN] You appear to be running FreeBSD."
 if [ ${MACHINE_TYPE} == 'amd64' ]; then
  echo "[DAMN] And 64bit, getting 64bit Blender"
  ftp http://download.blender.org/release/Blender2.56abeta/blender-2.56a-beta-FreeBSD-amd64.tbz
 else
  echo "[DAMN] And 32bit or other, picking 32bit to be sure."
  ftp http://download.blender.org/release/Blender2.56abeta/blender-2.56a-beta-FreeBSD-i386.tbz
 fi
 echo "[DAMN] Please install Blender, package is in this folder."
fi

fi


# This part does not work yet.
#if [ $1 ]; then
#if [ $1 == "mysql" ]; then
#mkdir -p ~/.damn/
# if [ ! -s "~./damn/settings.cfg" ]; then
#  echo "[DAMN] Writing configuration file."
#  echo "[database]" > ~/.damn/settings.cfg
#  echo "DATABASE_ENGINE = mysql" >> ~/.damn/settings.cfg
#  echo "DATABASE_NAME = damn" >> ~/.damn/settings.cfg
#  echo "DATABASE_USER = root" >> ~/.damn/settings.cfg
#  echo "DATABASE_PASSWORD = pw" >> ~/.damn/settings.cfg
#  echo "DATABASE_HOST =" >> ~/.damn/settings.cfg
#  echo "DATABASE_PORT =" >> ~/.damn/settings.cfg
# fi
#echo "[DAMN] Please open ~/.damn/settings.cfg and insert appropriate values."
#fi
#fi
